package com.tan.api.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tan.common.dto.user.UserCreateDto;
import com.tan.common.dto.user.UserUpdateDto;
import com.tan.common.query.user.UserQuery;
import com.tan.common.vo.user.UserPages;
import com.tan.core.response.ApiResponse;
import com.tan.user.service.ISysUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author Tan
 * @since 2025-01-27
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController {

    @Resource
    private ISysUserService userService;

    @GetMapping("/pages")
    public ApiResponse<IPage<UserPages>> userPages(UserQuery userQuery) {
        return ApiResponse.success(userService.userPages(userQuery));
    }

    @PostMapping("/create")
    public ApiResponse<Void> createUser(@RequestBody UserCreateDto userCreateDto) {
        userService.createUser(userCreateDto);
        return ApiResponse.success();
    }

    @PostMapping("/update")
    public ApiResponse<Void> updateUser(@RequestBody UserUpdateDto updateDto) {
        userService.updateUser(updateDto);
        return ApiResponse.success();
    }

    @PostMapping("/del/{userId}")
    public ApiResponse<Void> delUser(@PathVariable("userId") Long userId) {
        userService.delUser(userId);
        return ApiResponse.success();
    }


    @GetMapping("/users")
    public ApiResponse<List<UserPages>> getUsers() {
        return ApiResponse.success(userService.getUsersVo());
    }
}
